import React, { PureComponent, Fragment } from "react";
import { Picker, List, DatePicker } from "antd-mobile"
import { isNull } from "../../utils/helper"
import MyDatePickerFooter from "./MyForm/MyDatePickerFooter"
export default class MiDatePickerFooter extends PureComponent {
	constructor(props) {
		super(props);
		this.state = {

		}
	}
	componentWillReceiveProps(next) {
		let { isReset: oldReset } = this.props;
		let { isReset: newReset } = next;
		if (oldReset !== newReset && newReset) {
			this.setState({
				hasError: false
			})
		}
	}
	render() {
		let { getFieldDecorator, field, defaultFormData, label, required, disabled, readonly, show_label, list } = this.props;
		if (list && list.length > 0) {
			list = list.map(i => {
				return {
					...i,
					label: i.name,
					value: i.code
				}
			})
		}
		list = [list]
		let isDisabled = disabled == 1;
		let isReadonly = readonly == 1;
		let isShowLabel = isNull(show_label) || show_label == 1
		let { hasError, errorMsg } = this.state;
		let isRequired = required == 1;
		return (
			<div>
				{
					getFieldDecorator(field[0], {
						initialValue: defaultFormData[field[0]],
						rules: [
							{
								validator: (rule, value, callback) => {
									if (isRequired) {
										if (isNull(value)) {
											if (!hasError) {
												this.setState({
													hasError: true,
													errorMsg: "请选择：" + label
												})
												callback("请选择：" + label)
											}
										}
										else {
											this.setState({
												hasError: false,
												errorMsg: ""
											})
											callback()
										}
									}
									callback()
								}
							}
						]
					})(
						<MyDatePickerFooter {...this.props} hasError={hasError} errorMsg={errorMsg} />
					)
				}
			</div>
		)
	}
}
